﻿//建筑公共部位通用下拉框的获取
var uri = document.location.search;//接收页面传值
var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
var P_ReportNumber11 = uri.substr(i);//截取问号前面的值
$(function () {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Dictionary/GetHouseTypeList",
        async: false,
        data: {
            Dmenuid: [14, 15, 16, 17, 18, 19, 20, 21, 22]
        },
        success: function (data, status) {
            $("option").remove();
            $(data).each(function (i, obj) {
                $(obj).each(function (j, item) {
                    switch (item.Dmenuid) {
                        case 14:
                            $("#F_structureID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 15:
                            $("#F_TypesID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 16:
                            $("#F_facadeID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 17:
                            $("#F_commonalityID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 18:
                            $("#F_elevatorID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 19:
                            $("#F_supplyID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 20:
                            $("#F_waterID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 21:
                            $("#F_heatingID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                        case 22:
                            $("#F_entranceID").append("<option value=" + item.DictionaryID + ">" + item.DictionaryName + "</option>")
                            break;
                    }
                })
            })
            
        },
        error: function (e) {
            layer.msg('服务器链接超时!', { icon: 0, time: 1000 });
        },
        complete: function () {
        }
    })
})
//建筑公共部位状况的数据添加
function insertBuilding() {
    var F_structureID = $("#F_structureID option:checked").attr("value");      //房屋结构编号
    var F_TypesID = $("#F_TypesID option:checked").attr("value");              //房屋类型编号
    var F_facadeID = $("#F_facadeID option:checked").attr("value");            //外立面装饰编号
    var F_commonalityID = $("#F_commonalityID option:checked").attr("value");  //公共部位装修编号
    var F_elevatorID = $("#F_elevatorID option:checked").attr("value");        //电梯编号 
    var F_supplyID = $("#F_supplyID option:checked").attr("value");            //供气编号
    var F_waterID = $("#F_waterID option:checked").attr("value");              //供水编号
    var F_heatingID = $("#F_heatingID option:checked").attr("value");          //供暖编号
    var F_entranceID = $("#F_entranceID option:checked").attr("value");        //门禁编号
    var F_else = $("#F_else").val();                                  //其他
    var uri = document.location.search;//接收页面传值
    var i = uri.lastIndexOf("?") + 1;//获取问号前面的值
    var P_ReportNumber2 = uri.substr(i);//截取问号前面的值
    var parms = {
        F_structureID: F_structureID,//房屋结构编号
        F_TypesID: F_TypesID,//房屋类型编号
        F_facadeID: F_facadeID,//外立面装饰编号
        F_commonalityID: F_commonalityID,//公共部位装修编号
        F_elevatorID: F_elevatorID,//电梯编号 
        F_supplyID: F_supplyID,//供气编号
        F_waterID: F_waterID,//供水编号
        F_heatingID: F_heatingID,//供暖编号
        F_entranceID: F_entranceID,//门禁编号
        F_else: F_else,	     //其他
        P_ReportNumber: P_ReportNumber2
    }
    $.ajax({
        type: "post",
        url: ApiUrl + "api/Facility/Postinsert",
        data: parms,
        //contentType: 'application/json',
        success: function (data, status) {
            if (status == "success") {
                if (data == true) {
                    layer.msg('保存成功!', { icon: 1, time: 1000 });
                }
                else {
                    layer.msg('保存失败!', { icon: 2, time: 1000 });
                }
            }
        },
        error: function (e) {
            layer.msg('服务器链接超时!', { icon: 0, time: 1000 });
        },
        complete: function () {

        }
    })
}
//数据回填
$(function () {
    $.ajax({
        type: "get",
        url: ApiUrl + "api/Facility/SelectByid",
        data: { P_ReportNumber: P_ReportNumber11 },
        async: false,
        success: function (data, status) {
            if (status == "success") {
                if (data != null) {
                    $("#F_id           ").val(data.F_id)
                    $("#P_ReportNumber ").val(data.P_ReportNumber)
                    $("#F_structureID  ").val(data.F_structureID)
                    $("#F_TypesID      ").val(data.F_TypesID)
                    $("#F_facadeID     ").val(data.F_facadeID)
                    $("#F_commonalityID").val(data.F_commonalityID)
                    $("#F_elevatorID   ").val(data.F_elevatorID)
                    $("#F_supplyID     ").val(data.F_supplyID)
                    $("#F_waterID      ").val(data.F_waterID)
                    $("#F_heatingID    ").val(data.F_heatingID)
                    $("#F_entranceID   ").val(data.F_entranceID)
                    $("#F_else         ").val(data.F_else)
                    $("#F_state        ").val(data.F_state)
                }
            }
        },
        error: function (e) {
            layer.msg('服务器链接超时!', { icon: 2, time: 5000 });
        },
        complete: function () {

        }
    })
})